/*
 * SkillType.java
 *
 * Created on January 21, 2008, 8:13 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package wisp.dataObjects;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.util.Vector;
import java.lang.Exception.*;
/**
 *
 * @author Nezie Santos
 */
public class SkillType {
     private dbConnection dbcon = new dbConnection();
     private String skillName, classType, sType, skType, sDes, spic;
     private int skillLevel, mpreq, sWeight, atkType;
     private double str, mpgr, hpgr,atk, matk, spd,currentHP, vit, healPt, maxMP, currentMP;
    /** Creates a new instance of SkillType */
    public SkillType() {
    }
     public SkillType(String skillNames, String stype, String des, int aType, String sktpe, String cclass, int skillLevels, double strs,double mpgrs,double hpgrs,double atks,double matks, double spds,double currentHPs,double vits, double healPts,double  maxMPs, double currentMPs) {
         this.setAtk(atks);
         setSkType(sktpe);
         sDes = des;
         this.setCurrentHP(currentHPs);
         this.setCurrentMP(currentMPs);
         this.setHealPt(healPts);
         this.setHpgr(hpgrs);
         this.setMatk(matks);
         this.setMaxMP(maxMPs);
         this.setMpgr(mpgrs);
         this.setSkillLevel(skillLevels);
         this.setSkillName(skillNames);
         this.setSpd(spds);
         this.setStr(strs);
         this.setVit(vits);
         this.setClassType(cclass);
         this.setAtkType(aType);
         sType = stype;
    }
    
    public Vector viewSkillLevel (int slvl, String ctype)
    {
        //Statement stmt;
        String query;
        ResultSet rs;
        PreparedStatement stmt;
        Vector<SkillType> sList;
            
        sList = new Vector<SkillType>();
        Iterator it =sList.iterator();
                
        getDbcon().connect();
        query = "SELECT * FROM SkillType WHERE skillLevel <= ? AND classType = ?";
        
        try
        {
            stmt = getDbcon().con.prepareStatement(query);
            stmt.setInt(1, slvl);
            stmt.setString(2, ctype);
            rs = stmt.executeQuery();	
        
            while (rs.next()) 
            {	
                SkillType s = new SkillType();
                s.sDes = rs.getString("sDes");
                 s.setAtk(rs.getDouble("atk"));
                 s.setCurrentHP(rs.getDouble("currentHP"));
                 s.setCurrentMP(rs.getDouble("currentMP"));
                 s.setHealPt(rs.getDouble("healPt"));
                 s.setHpgr(rs.getDouble("hpgr"));
                 s.setMatk(rs.getDouble("matk"));
                 s.setMaxMP(rs.getDouble("maxMP"));
                 s.setMpgr(rs.getDouble("mpgr"));
                 s.setSkillLevel(rs.getInt("skillLevel"));
                 s.setSkillName(rs.getString("skillName"));
                 s.setSpd(rs.getDouble("spd"));
                 s.setStr(rs.getDouble("str"));
                 s.setVit(rs.getDouble("vit"));
                 s.setClassType(rs.getString("classType"));
                 s.setSType(rs.getString("sType"));
                 s.setMpreq(rs.getInt("mpreq"));
                 s.setSkType(rs.getString("skType"));
                 s.sWeight = rs.getInt("sWeight");
                 s.setAtkType(rs.getInt("atkType"));
                  s.setSpic(rs.getString("spic"));
                sList.add(s);
               
             }
            //crset.populate(rs);
            rs.close(); 					
            stmt.close();
            return sList;
 				
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
       finally {
            getDbcon().disconnect();
        }
        return null;
     }
    
    public Vector viewAllSkills()
    {
        String query;
        ResultSet rs;
        PreparedStatement stmt;
        Vector<SkillType> sList;
            
        sList = new Vector<SkillType>();
        Iterator it =sList.iterator();
                
        getDbcon().connect();
        query = "SELECT * FROM SkillType";
        
        try
        {
            stmt = getDbcon().con.prepareStatement(query);
            rs = stmt.executeQuery();	
        
            while (rs.next()) 
            {	
                SkillType s = new SkillType();
                s.sDes = rs.getString("sDes");
                 s.setAtk(rs.getDouble("atk"));
                 s.setCurrentHP(rs.getDouble("currentHP"));
                 s.setCurrentMP(rs.getDouble("currentMP"));
                 s.setHealPt(rs.getDouble("healPt"));
                 s.setHpgr(rs.getDouble("hpgr"));
                 s.setMatk(rs.getDouble("matk"));
                 s.setMaxMP(rs.getDouble("maxMP"));
                 s.setMpgr(rs.getDouble("mpgr"));
                 s.setSkillLevel(rs.getInt("skillLevel"));
                 s.setSkillName(rs.getString("skillName"));
                 s.setSpd(rs.getDouble("spd"));
                 s.setStr(rs.getDouble("str"));
                 s.setVit(rs.getDouble("vit"));
                 s.setClassType(rs.getString("classType"));
                 s.setSType(rs.getString("sType"));
                 s.setMpreq(rs.getInt("mpreq"));
                 s.setSkType(rs.getString("skType"));
                 s.sWeight = rs.getInt("sWeight");
                 s.setAtkType(rs.getInt("atkType"));
                    s.setSpic(rs.getString("spic"));
                sList.add(s);
               
             }
            //crset.populate(rs);
            rs.close(); 					
            stmt.close();
            return sList;
 				
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
       finally {
            getDbcon().disconnect();
        }
        return null;
    }
    
    public Vector viewNextSkill (int lvl, String cname, String cclass)
    {
        //Statement stmt;
        String query;
        ResultSet rs;
        PreparedStatement stmt;
        Vector<SkillType> sList;
            
        sList = new Vector<SkillType>();
        Iterator it =sList.iterator();
        getDbcon().connect();
        query = "SELECT * FROM SkillType WHERE classType = ? AND skillLevel <= ? AND skillName NOT IN (SELECT skillName FROM Skill WHERE characterName = ?)";
       
        try
        {
            stmt = getDbcon().con.prepareStatement(query);
            stmt.setString(1, cclass);
            stmt.setInt(2, lvl);
            stmt.setString(3, cname);
            rs = stmt.executeQuery();	
        
            while (rs.next()) 
            {	
                SkillType s = new SkillType();
                s.sDes = rs.getString("sDes");
                s.setAtk(rs.getDouble("atk"));
                 s.setCurrentHP(rs.getDouble("currentHP"));
                 s.setCurrentMP(rs.getDouble("currentMP"));
                 s.setHealPt(rs.getDouble("healPt"));
                 s.setHpgr(rs.getDouble("hpgr"));
                 s.setMatk(rs.getDouble("matk"));
                 s.setMaxMP(rs.getDouble("maxMP"));
                 s.setMpgr(rs.getDouble("mpgr"));
                 s.setSkillLevel(rs.getInt("skillLevel"));
                 s.setSkillName(rs.getString("skillName"));
                 s.setSpd(rs.getDouble("spd"));
                 s.setStr(rs.getDouble("str"));
                 s.setVit(rs.getDouble("vit"));
                 s.setClassType(rs.getString("classType"));
                 s.setSType(rs.getString("sType"));
                 s.setMpreq(rs.getInt("mpreq"));
                 s.setSkType(rs.getString("skType"));
                  s.sWeight = rs.getInt("sWeight");
                 s.setAtkType(rs.getInt("atkType"));
                    s.setSpic(rs.getString("spic"));
                 sList.add(s);
             }
            rs.close(); 					
            stmt.close();
            it = sList.iterator();
            SkillType sk = new SkillType ();
            Vector<SkillType> fList = new Vector();
            String skill = "nyah";
            while (it.hasNext())
            {   
                sk = sList.firstElement();
                if (!skill.equals(sk.getSkType()))
                {
                    skill = sk.getSkType();
                    //System.out.println(" --->" +sk.getSkillName());
                    fList.add(sk);            
                }
                sList.remove(sk);
            }
            return fList;
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
       finally {
            getDbcon().disconnect();
        }
        return null;
     }
    public void viewSkill (String sname){
        String query;
        ResultSet rs;
        PreparedStatement stmt;
                
        getDbcon().connect();
        query = "SELECT * FROM SkillType WHERE skillName = ?";
        
        try
        {
            stmt = getDbcon().con.prepareStatement(query);
            stmt.setString(1, sname);
            rs = stmt.executeQuery();	
        
            while (rs.next()) 
            {
                this.sDes = rs.getString("sDes");
                 this.setAtk(rs.getDouble("atk"));
                 this.setCurrentHP(rs.getDouble("currentHP"));
                 this.setCurrentMP(rs.getDouble("currentMP"));
                 this.setHealPt(rs.getDouble("healPt"));
                 this.setHpgr(rs.getDouble("hpgr"));
                 this.setMatk(rs.getDouble("matk"));
                 this.setMaxMP(rs.getDouble("maxMP"));
                 this.setMpgr(rs.getDouble("mpgr"));
                 this.setSkillLevel(rs.getInt("skillLevel"));
                 this.setSkillName(rs.getString("skillName"));
                 this.setSpd(rs.getDouble("spd"));
                 this.setStr(rs.getDouble("str"));
                 this.setVit(rs.getDouble("vit"));
                 this.setClassType(rs.getString("classType"));
                 this.setSType(rs.getString("sType"));
                 this.setMpreq(rs.getInt("mpreq"));
                 this.setSkType(rs.getString("skType"));
                 this.setAtkType(rs.getInt("atkType"));
                  this.sWeight = rs.getInt("sWeight");
                     this.setSpic(rs.getString("spic"));
            }
            rs.close(); 					
            stmt.close();
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
        finally {
            getDbcon().disconnect();
 
        }
    }

    public dbConnection getDbcon() {
        return dbcon;
    }

    public void setDbcon(dbConnection dbcon) {
        this.dbcon = dbcon;
    }

    public String getSkillName() {
        return skillName;
    }

    public void setSkillName(String skillName) {
        this.skillName = skillName;
    }

    public String getClassType() {
        return classType;
    }

    public void setClassType(String classType) {
        this.classType = classType;
    }

    public int getSkillLevel() {
        return skillLevel;
    }

    public void setSkillLevel(int skillLevel) {
        this.skillLevel = skillLevel;
    }

    public double getStr() {
        return str;
    }

    public void setStr(double str) {
        this.str = str;
    }

    public double getMpgr() {
        return mpgr;
    }

    public void setMpgr(double mpgr) {
        this.mpgr = mpgr;
    }

    public double getHpgr() {
        return hpgr;
    }

    public void setHpgr(double hpgr) {
        this.hpgr = hpgr;
    }

    public double getAtk() {
        return atk;
    }

    public void setAtk(double atk) {
        this.atk = atk;
    }

    public double getMatk() {
        return matk;
    }

    public void setMatk(double matk) {
        this.matk = matk;
    }

    public double getSpd() {
        return spd;
    }

    public void setSpd(double spd) {
        this.spd = spd;
    }

    public double getCurrentHP() {
        return currentHP;
    }

    public void setCurrentHP(double currentHP) {
        this.currentHP = currentHP;
    }

    public double getVit() {
        return vit;
    }

    public void setVit(double vit) {
        this.vit = vit;
    }

    public double getHealPt() {
        return healPt;
    }

    public void setHealPt(double healPt) {
        this.healPt = healPt;
    }

    public double getMaxMP() {
        return maxMP;
    }

    public void setMaxMP(double maxMP) {
        this.maxMP = maxMP;
    }

    public double getCurrentMP() {
        return currentMP;
    }

    public void setCurrentMP(double currentMP) {
        this.currentMP = currentMP;
    }

    public String getSType() {
        return sType;
    }

    public void setSType(String sType) {
        this.sType = sType;
    }

    public int getMpreq() {
        return mpreq;
    }

    public void setMpreq(int mpreq) {
        this.mpreq = mpreq;
    }

    public String getSkType() {
        return skType;
    }

    public void setSkType(String skType) {
        this.skType = skType;
    }

    public String getSDes() {
        return sDes;
    }

    public void setSDes(String sDes) {
        this.sDes = sDes;
    }

    public int getSWeight() {
        return sWeight;
    }

    public void setSWeight(int sWeight) {
        this.sWeight = sWeight;
    }

    public int getAtkType() {
        return atkType;
    }

    public void setAtkType(int atkType) {
        this.atkType = atkType;
    }

    public String getSpic() {
        return spic;
    }

    public void setSpic(String spic) {
        this.spic = spic;
    }
}
